
    <div class="content margin_top">
        <header class="header fixed_top bg_mx_green"></header>
        <form class="cost_input"></form>
    </div>
    <div class="toast"></div>
    <!-- toast模版 -->
    <script type="text/template" charset="utf-8" id='toast_template'>
        <i class="iconfont icon-toast{{=it.icon}}"></i>
        <div class="toast_text">{{=it.text}}</div>
    </script>
    <script type="text/template" charset="utf-8" id='info_template'>
        <div class="bg_white margin_b_10">
            <div class="row border_b padding_10_15">
                <div class="flex col_6">
                    <div class="width_70">类目</div>
                    <div class="left_70 light">
                        <!--<input type="text" name="type" placeholder="花费类型" request title="花费类型">-->
                        <select class="select2" name="typeid" id="">
                            <{foreach $types as $key => $row  }>
                                <option value="<{$row['id']}>"><{$row['name']}></option>
                            <{/foreach}>
                        </select>
                        <input type="hidden" name="pigid">
                    </div>
                </div>
                <div class="flex col_6">
                    <div class="width_70">价格(元)</div>
                    <div class="left_70 light">
                        <input type="text" name="price" placeholder="价格" request title="价格" data-pattern="^[0-9]+(.[0-9]{1,2})?$" data-tips="最多两位小数的数字">
                    </div>
                </div>
            </div>
            <div class="border_b v_center padding_10_15">
                <div class="width_70">时间</div>
                <div class="left_70 light">
                    <input class="padding_v_5" type="date" name="createtime" value="{{=it}}" placeholder="时间" request title="时间">
                </div>
            </div>
            <div class="text_info padding_10_15">
                <textarea name="description" placeholder="请输入详细情况"></textarea>
            </div>
        </div>
        <div class="padding_15 font_16">
            <button class="btn btn_mx_green all_width lineheight_3">保存</button>
        </div>
        <input name="_csrf" type="hidden" id="_csrf" value="<{$app->request->csrfToken}>">
    </script>
    <script>
        // 页面初始化
            var evalinfo = doT.template($("#info_template").text());
            var evalToast = doT.template($("#toast_template").text());
            var date_now = new Date();
            var d = date_now.getFullYear()+'-'+f(date_now.getMonth()+1)+'-'+f(date_now.getDate());
            loaddata(".cost_input",evalinfo,d);
            loadheadbar("添加成本",1)
        // 提交表单
            var submited = false;
            $(".cost_input").submit(function(e){
                e.preventDefault();
                var pigid = GetQueryString("pigid");
                $("input[name=pigid]").val(pigid)
                with(this){
                    for (var i = 0; i < this.length; i++) {
                        if($(this[i]).attr("request")==""){
                            if(!checkone(this[i])){
                                return false;
                            }
                        }
                    }
                    if(submited) return false;
                    var data = $(".cost_input").serialize();
                    $.post("/business/person/post-cost",data,function(res){console.log(res);
                        submited = true;
                        toast("attention",res.msg)
                        if(!res.status){
                            location.href='/business/person/pig'
                        }
                    },"json")
                }
            })
    </script>